package com.yaozheng.vocationaltraining.view;

import android.app.Dialog;
import android.content.Context;
import android.view.Display;
import android.view.LayoutInflater;
import android.view.View;
import android.view.WindowManager;
import android.widget.FrameLayout;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;

import com.yaozheng.vocationaltraining.R;
import com.yaozheng.vocationaltraining.adapter.PKSaiKuangListAdapter;
import com.yaozheng.vocationaltraining.bean.PKSaiKuangBean;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by moon on 2017/11/19.
 */

public class PKSaiKuangDialog {
    private Context context;
    private Dialog dialog;
    private LinearLayout lLayout_bg;
    //    private TextView txt_title;
//    private TextView txt_msg;
//    private Button btn_neg;
//    private Button btn_pos;
    private ImageView closed_imageview;
    private Display display;
//    private boolean showTitle = false;
//    private boolean showMsg = false;
//    private boolean showPosBtn = false;
//    private boolean showNegBtn = false;

    private ListView listView;
    private List<PKSaiKuangBean> dataList = new ArrayList<>();
    private PKSaiKuangListAdapter adapter;

    public PKSaiKuangDialog(Context context) {
        this.context = context;
        WindowManager windowManager = (WindowManager) context
                .getSystemService(Context.WINDOW_SERVICE);
        display = windowManager.getDefaultDisplay();
    }

    public PKSaiKuangDialog builder() {
        //
        View view = LayoutInflater.from(context).inflate(
                R.layout.view_pk_saikuang_dailog, null);

        //
        lLayout_bg = (LinearLayout) view.findViewById(R.id.lLayout_bg);
        closed_imageview = (ImageView) view.findViewById(R.id.closed_imageview);
        listView = (ListView) view.findViewById(R.id.listView);
//        txt_title.setVisibility(View.GONE);
//        txt_msg = (TextView) view.findViewById(R.id.txt_msg);
//        txt_msg.setVisibility(View.GONE);
//        btn_neg = (Button) view.findViewById(R.id.btn_neg);
//        btn_neg.setVisibility(View.GONE);
//        btn_pos = (Button) view.findViewById(R.id.btn_pos);
//        btn_pos.setVisibility(View.GONE);
//        img_line = (ImageView) view.findViewById(R.id.img_line);
//        img_line.setVisibility(View.GONE);

        //
        dialog = new Dialog(context, R.style.AlertDialogStyle);
        dialog.setContentView(view);

        //
        lLayout_bg.setLayoutParams(new FrameLayout.LayoutParams((int) (display
                .getWidth() * 0.85), LinearLayout.LayoutParams.WRAP_CONTENT));


        adapter = new PKSaiKuangListAdapter(context,dataList);
        listView.setAdapter(adapter);

        closed_imageview.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                dialog.dismiss();
            }
        });
        return this;
    }

    public void setDataList(List<PKSaiKuangBean> dataList){
        adapter.setData(dataList);
        adapter.notifyDataSetChanged();
    }

    public void show() {
        // setLayout();
        dialog.show();
    }
}
